package cn.gglol.jvvtool.event;

import cn.gglol.jvvtool.jedis.cache.event.RefreshEventListener;
import org.springframework.stereotype.Component;
import redis.clients.jedis.JedisCluster;

import javax.annotation.Resource;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.logging.Logger;

/**
 * @author jvvtao
 * @version 1.0
 * @project Name: jvvtool
 * @file Name: TimeRefreshEventListener
 * @desc 功能描述
 * @date 2021/9/2
 * @time 18:26
 * @by IDE: IntelliJ IDEA
 */
@Component
public class TimeRefreshEventListener extends RefreshEventListener<TimeRefreshEvent> {
    Logger logger = Logger.getLogger(this.getClass().getName());

    @Resource
    private JedisCluster jedisCluster;

    @Override
    public void onApplicationEvent(TimeRefreshEvent event) {
        logger.info(event.getRedisKey().toString());

        jedisCluster.set(event.getRedisKey().getFinalKey(), LocalTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME));
    }
}
